home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-10-25 | 1.9 KB | 36 lines | [TEXT/MPS ] |
- ;
- ; DoubleTrouble - by Greg Marriott
- ;
- ; © 1992, Apple Computer, Inc.
- ;
- ; DoubleTrouble is a debugging utility made to catch a common programming error:
- ; freeing a handle that has already been freed. (I call these errors “double
- ; dispose bugs”…)
- ;
- ; When _DisposeHandle is called on a handle, the memory manager adds the handle
- ; to its “free list,” a linked list of handles available for the allocator to use.
- ; Calling _DisposeHandle on that handle again is usually benign. The memory
- ; manager dereferences the handle, pointing to the next handle in the free list.
- ; If the the dereferenced handle points to the first handle in a master pointer block,
- ; however, the handle appears valid because it points to a real block. The memory
- ; manager fails to realize the block is NOT a relocatable block (all master pointer
- ; blocks are nonrelocatable), and marks it free (yikes!). The freed master pointer
- ; block is then used in a future allocation (usually very soon after being freed).
- ; This mangles several master pointers and the free list. Crashes soon follow.
- ;
- ; This kind of bug is very hard to track down, and usually difficult to reproduce,
- ; because master pointer blocks contain 64 handles (by default, some programs
- ; change this behavior). So, this situation only comes up about 1/64th of the
- ; time. When it happens, though, the results are inevitably catastrophic.
- ;
- ; DoubleTrouble compares each handle being disposed to every handle in the free list of
- ; the zone containing the handle. If the handle is already in the free list,
- ; DoubleTrouble breaks into the debugger with a message indicating what’s going on.
- ; Continuing execution will stuff memWZErr (WhichZone failed, -111) into MemErr
- ; and d0 and return to the caller (and NOT call through to _DisposeHandle).
- ;
- ; Greg Marriott
- ; Just Some Guy
- ; Apple Computer, Inc.
- ; 20525 Mariani Ave. MS/81-GC
- ; Cupertino, CA 95014